package com.tianbing.adlottery.controller.validation;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.fengniu.ejb.dao.IContentDao;
import com.fengniu.ejb.dao.ISiteDao;
import com.fengniu.ejb.dao.IUserDao;
import com.fengniu.ejb.entity.Content;
import com.fengniu.ejb.entity.Site;
import com.fengniu.ejb.entity.User;
import com.tianbing.adlottery.controller.storeadmin.AdminMyStoreController;

/**
 * MultiActionController for the user��site��content validation.
 * 
 * @author Conan Chen
 * @since 2008.01.03
 */
public class ValidationController extends MultiActionController {
	Logger logger = Logger.getLogger(AdminMyStoreController.class.getName());

	private String validateUserResultView;

	private String validateSiteResultView;

	private String validateContentResultView;

	private IUserDao userDao;

	private ISiteDao siteDao;

	private IContentDao contentDao;

	public ModelAndView isExistUserId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(validateUserResultView);
		Map<String, Object> model = mv.getModel();
		String userId = ServletRequestUtils.getStringParameter(request, "uid", null);
		User user = userDao.findUserByUserId(userId);
		model.put("user", user);
		return mv;
	}

	public ModelAndView isExistSiteId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(validateSiteResultView);
		Map<String, Object> model = mv.getModel();
		String siteId = ServletRequestUtils.getStringParameter(request, "sid", null);
		Site site = siteDao.findSiteBySiteId(siteId);
		model.put("site", site);
		return mv;
	}

	public ModelAndView isExistContentId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(validateContentResultView);
		Map<String, Object> model = mv.getModel();
		String contentId = ServletRequestUtils.getStringParameter(request, "cid", null);
		Content content = contentDao.findContentByContentId(contentId);
		model.put("content", content);
		return mv;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public void setValidateUserResultView(String validateUserResultView) {
		this.validateUserResultView = validateUserResultView;
	}

	public void setValidateSiteResultView(String validateSiteResultView) {
		this.validateSiteResultView = validateSiteResultView;
	}

	public void setValidateContentResultView(String validateContentResultView) {
		this.validateContentResultView = validateContentResultView;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void setSiteDao(ISiteDao siteDao) {
		this.siteDao = siteDao;
	}

	public void setContentDao(IContentDao contentDao) {
		this.contentDao = contentDao;
	}
}
